package A1;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: Sarah
 * Date: 17/08/2011
 * Time: 2:39:10 PM
 * To change this template use File | Settings | File Templates.
 */


public class elevator extends JPanel {
    int numOfFloor;

    JButton openButton, closeButton;
    JButton[] stopButton;

    /**
     * Sets the elevator background colour
     * Sets and displays the internal elevator buttons
     */
    public elevator(int numOfFloor) {
        this.numOfFloor = numOfFloor;

        setBackground(Color.LIGHT_GRAY);
        closeButton = new JButton("|> <|");
        openButton = new JButton("<| |>");
        stopButton = new JButton[numOfFloor + 1];
        for (int i = numOfFloor; i >= 1; i--)
            stopButton[i] = new JButton(String.valueOf(i));

        setLayout(new GridLayout((numOfFloor + 3) / 2, 2, 10, 10));
        if (numOfFloor % 2 == 1)
            add(new JButton());

        for (int i = numOfFloor; i >= 1; i--)
            add(stopButton[i]);

        add(openButton);
        add(closeButton);
	}
}
